package marmalius;


public class Farming {

    public int rakeTime = 10;
    public int farmTime = 0;
    public int treeRakeTime = 10;
    public boolean treePatch = false;
    public int herbType = 0;
    public int treeFarmTime = 0;
    public boolean checkHealth = false;
    public boolean isRaking = false;

    public void raking(int playerID) {
        client p = (client) PlayerHandler.getInstance().getPlayer(playerID);

        if (p.playerHasItem(5341) && rakeTime == 10 || treeRakeTime == 10) {
            p.startAnimation(2273);
            isRaking = true;
            p.sendMessage("You Begin raking the patch");
        } else if (!p.playerHasItem(5341)) {
            p.sendMessage("You need a rake to weed this patch");
        }
    }	

    public void herbSeeds(String seedName, int seedId, int playerID, int growTime, int levelReq, int XP) {
        client p = (client) PlayerHandler.getInstance().getPlayer(playerID);

        if (p.playerLevel[19] >= levelReq && p.playerHasItem(seedId)
                && farmTime == 0) {
            p.deleteItem(seedId, p.getItemSlot(seedId), 1);
            p.addSkillXP(XP, 19);
            p.startAnimation(2272);
            p.sendMessage("You plant the " + seedName + " seed.");
            farmTime = growTime;
            p.replaceObject(8140, 3103, 3097, 0, 10);
        } else if (p.playerLevel[19] < levelReq) {
            p.sendMessage(
                    "You need a farming level of " + levelReq + " to plant this");
        }
    }	

    public void pickHerbs(String herbName, int herbId, int playerID, int XP) {
        client p = (client) PlayerHandler.getInstance().getPlayer(playerID);

        p.addItem(herbId, 1 + misc.random(7));
        p.addSkillXP(XP * 2, 19);
        p.startAnimation(2272);
        p.sendMessage("You pick the " + herbName);
        p.replaceObject(8135, 3103, 3097, 0, 10);
    }

    // END HERBS
    // START TREES
    public void growSapling(int seedId, String saplingName, int saplingId, int playerID) {
        client p = (client) PlayerHandler.getInstance().getPlayer(playerID);

        p.addItem(saplingId, 1);
        p.deleteItem(seedId, p.getItemSlot(seedId), 1);
        p.deleteItem(5354, p.getItemSlot(5354), 1);
        p.sendMessage("You plant the " + saplingName + " in the pot");
    }

    public void plantTree(String treeName, int saplingId, int playerID, int growTime, int levelReq, int XP, int treeId) {
        client p = (client) PlayerHandler.getInstance().getPlayer(playerID);

        if (p.playerLevel[19] >= levelReq && p.playerHasItem(saplingId)
                && farmTime == 0) {
            p.deleteItem(saplingId, p.getItemSlot(saplingId), 1);
            p.addSkillXP(XP, 19);
            p.startAnimation(2272);
            p.sendMessage("You plant the " + treeName + " sapling.");
            treeFarmTime = growTime;
            p.replaceObject(treeId, 3219, 3428, 0, 10);
        } else if (p.playerLevel[19] < levelReq) {
            p.sendMessage(
                    "You need a farming level of " + levelReq + " to plant this");
        }
    }
	
    public void grownTree(int treeId, int playerID) {
        client p = (client) PlayerHandler.getInstance().getPlayer(playerID);

        if (treeFarmTime == 1) {
            p.replaceObject(treeId, 3219, 3428, 0, 10);
            p.sendMessage("Your tree is now fully grown!");
            treeFarmTime = 0;
        }
    }

    public void checkHealth(String treeName, int XP, int playerID) {
        client p = (client) PlayerHandler.getInstance().getPlayer(playerID);

        if (checkHealth == false) {
            p.addSkillXP(XP, 19);
            p.startAnimation(2274);
            p.sendMessage(
                    "You check the " + treeName
                    + " tree and find it's in perfect health");
            checkHealth = true;
        } else if (checkHealth == true) {
            p.sendMessage("You've already checked this trees health!");
            p.sendMessage("Inspect it to clear the patch!");
        }
    }
}
